﻿//-------------------------------------------------------------------
//版权所有：版权所有(C) 2010， YIBO(China) Studio 
//系统名称：验证控件
//文件名称：CompareClientValidator.cs
//模块名称：验证控件
//模块编号：
//作　　者：LHC
//完成日期：2010/8/29 14:34:00
//功能说明：
//-----------------------------------------------------------------
//修改记录：
//修改人：  
//修改时间：
//修改内容：
//-------------------------------------------------------------------
#region 程序集 YIBO.Validator, v1.0.100829

using System.Globalization;
using System.Web.UI.WebControls;

#endregion

namespace MvcMall.Framework.FormValidator
{
   
    /// <summary>
    /// 比较验证
    /// </summary>
    public class CompareClientValidator : ClientValidator
    {
        /// <summary>
        /// 控件标识
        /// </summary>
        private string destinationId;

        /// <summary>
        /// 创建控件容器
        /// </summary>
        /// <returns>返回容器对象</returns>
        internal override ValidateRenderControl GenerateAppendScript()
        {
            ///创建验证控件容器
            ValidateRenderControl control = new ValidateRenderControl();
            ///获取当前控件对象
            WebControl control2 = (WebControl) base.Owner.NamingContainer.FindControl(this.DestinationId);
            if (control2 != null)
            {   
                control.Text = string.Format(CultureInfo.InvariantCulture, "appendValid(new CompareValidator('{0}', '{1}', '{2}'));", new object[] { base.Owner.TargetClientId, control2.ClientID, this.ErrorMessage });
            }
            return control;
        }

        /// <summary>
        /// 注册验证规则
        /// </summary>
        /// <returns>返回输出容器</returns>
        internal override ValidateRenderControl GenerateInitScript()
        {
            ValidateRenderControl control = new ValidateRenderControl();
            WebControl control2 = (WebControl) base.Owner.NamingContainer.FindControl(this.DestinationId);
            if (control2 != null)
            {
                control.Text = string.Format(CultureInfo.InvariantCulture, "initValid(new CompareValidator('{0}', '{1}', '{2}'));", new object[] { base.Owner.TargetClientId, control2.ClientID, this.ErrorMessage });
            }
            return control;
        }

        /// <summary>
        /// 唯一标识
        /// </summary>
        public string DestinationId
        {
            get
            {
                return this.destinationId;
            }
            set
            {
                this.destinationId = value;
            }
        }
    }
}

